import axios from 'axios';
import type { UserState } from '@/store/modules/user/types';

export interface MemberRecord extends Partial<UserState> {
  index?: number;
  projectAdmin?: number;
  moduleVisible?: string | string[];
  projectId?: string;
  userId?: string;
}

export interface MemberListParams {
  projectId?: string;
  name?: string;
  accountState?: number;
  pageSize: number;
  pageNo?: number;
  current?: number;
}

// 获取项目下的成员列表
export function getMemberList(params: MemberListParams) {
  return axios.get('/cde-collaboration/project/getUsers', {
    params,
  });
}

// 新增项目成员
export function addMember(data: MemberRecord) {
  return axios.post('/cde-collaboration/project/saveUser', data);
}

// 修改项目成员信息
export function updateMember(data: MemberRecord) {
  return axios.post('/cde-collaboration/project/updateUser', data);
}

// 移除项目成员
export function removeMember(projectId: string, userId: string) {
  return axios.delete('/cde-collaboration/project/removeUser', {
    params: {
      projectId,
      userId,
    },
  });
}

// 发送邀请
export function sendInvite(projectId: string, userId: string) {
  axios.defaults.baseURL = '';
  return axios.post('/cde-collaboration/project/removeUser', {
    projectId,
    userId,
  });
}

// 导入成员
export function importMember(data: any) {
  axios.defaults.baseURL = '';
  return axios.post('/loc/project/importUser', data, {
    headers: { 'Content-Type': 'multipart/form-data' },
  });
}
